<template>
  <div class="container">
    <el-card>
      <template #header>
        <h3>用户报修</h3>
      </template>
      <el-form
        ref="form"
        class="demo-form-inline"
        :inline="true"
        :model="queryForm"
        @submit.native.prevent
      >
        <el-form-item>
          <el-select v-model="value1" placeholder="骑行区域">
            <el-option
              v-for="item in options1"
              :key="item.value"
              aria-setsize="medium"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input placeholder="用户昵称/用户手机号" />
        </el-form-item>
        <el-form-item>
          <el-input placeholder="车牌号" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('form')">查询</el-button>
          <el-button @click="resetForm('form')">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table
        ref="tableSort"
        v-loading="listLoading"
        :border="border"
        :data="list"
        @selection-change="setSelectRows"
      >
        <el-table-column align="center" type="selection" width="55" />
        <el-table-column
          align="center"
          label="序号"
          show-overflow-tooltip
          width="55"
        >
          <!-- 序号内容的列 -->
          <template #default="{ $index }">
            {{ $index + 1 }}
          </template>
        </el-table-column>
        <el-table-column
          v-for="(item, index) in finallyColumns"
          :key="index"
          align="center"
          :label="item.label"
          :sortable="item.sortable"
        >
          <!-- 的列 -->
          <template #default="{ row }">
            <span>{{ row[item.prop] }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="操作"
          show-overflow-tooltip
          width="100"
        >
          <template #default="{ row }">
            <el-button plain type="white" @click="handleEdit(row)">
              详情
            </el-button>
          </template>
        </el-table-column>
        <template #empty>
          <el-image
            class="vab-data-empty"
            :src="require('@/assets/empty_images/data_empty.png')"
          />
        </template>
      </el-table>
      <el-pagination
        background
        :current-page="queryForm.pageNo"
        :layout="layout"
        :page-size="queryForm.pageSize"
        :total="total"
        @current-change="handleCurrentChange"
        @size-change="handleSizeChange"
      />
    </el-card>
  </div>
</template>

<script>
  import { getList } from '@/api/table'
  export default {
    data() {
      return {
        options1: [
          { value: '选项1', label: '黄金糕' },
          { value: '选项2', label: '双皮奶' },
          { value: '选项3', label: '蚵仔煎' },
          { value: '选项4', label: '龙须面' },
          { value: '选项5', label: '北京烤鸭' },
        ],
        value1: '',
        checkList: [
          '区域名称',
          '用户昵称',
          '用户手机号',
          '车牌号',
          '创建时间',
          '故障部位',
          '故障描述',
          '是否已读',
        ],
        columns: [
          {
            label: '姓名',
            width: 'auto',
            prop: 'order',
            sortable: true,
            disableCheck: true,
          },
          {
            label: '用户昵称',
            width: 'auto',
            prop: 'city',
            sortable: true,
          },
          {
            label: '用户手机号',
            width: 'auto',
            prop: 'rate',
            sortable: true,
          },
          {
            label: '车牌号',
            width: '200',
            prop: 'phone',
            sortable: true,
          },
          {
            label: '创建时间',
            width: 'auto',
            prop: 'number',
            sortable: true,
          },
          {
            label: '故障部位',
            width: 'auto',
            prop: 'origin',
            sortable: true,
          },
          {
            label: '故障描述',
            width: 'auto',
            prop: 'origin',
            sortable: true,
          },
          {
            label: '是否已读',
            width: 'auto',
            prop: 'origin',
            sortable: true,
          },
        ],
        list: [],
        imageList: [],
        border: '',
        // 加载状态
        listLoading: false,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        // 初始状态下跳转页面的数据
        queryForm: {
          pageNo: 1,
          pageSize: 10,
          title: '',
        },
      }
    },
    computed: {
      dragOptions() {
        return {
          animation: 600,
          group: 'description',
        }
      },
      finallyColumns() {
        return this.columns.filter((item) =>
          this.checkList.includes(item.label)
        )
      },
    },
    created() {
      this.fetchData()
    },
    methods: {
      submitForm() {},
      resetForm() {},
      setSelectRows(val) {
        this.selectRows = val
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      handleReset() {},
      handleQuery() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data } = await getList(this.queryForm)
        const { list, total } = data
        this.list = list
        const imageList = []
        list.forEach((item) => {
          imageList.push(item.img)
        })
        this.imageList = imageList
        this.total = total
        this.listLoading = false
      },
    },
  }
</script>

<style></style>
